home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Component;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.awt.Rectangle;
- import java.awt.image.ImageObserver;
-
- public class mascot extends Applet implements Runnable {
- private Thread m_mascot;
- private Graphics m_Graphics;
- private Image[] m_Images;
- private int m_nCurrImage;
- private int m_nImgWidth;
- private int m_nImgHeight;
- private boolean m_fAllLoaded;
- private final int NUM_IMAGES = 18;
- public int speed;
- public int direction;
-
- public void stop() {
- if (this.m_mascot != null) {
- this.m_mascot.stop();
- this.m_mascot = null;
- }
-
- }
-
- public void paint(Graphics g) {
- if (this.m_fAllLoaded) {
- Rectangle r = g.getClipRect();
- g.clearRect(r.x, r.y, r.width, r.height);
- this.displayImage(g);
- } else {
- g.drawString("Loading images...", 10, 20);
- }
-
- }
-
- public void destroy() {
- }
-
- private void displayImage(Graphics g) {
- if (this.m_fAllLoaded) {
- g.drawImage(this.m_Images[this.m_nCurrImage], (((Component)this).size().width - this.m_nImgWidth) / 2, (((Component)this).size().height - this.m_nImgHeight) / 2, (ImageObserver)null);
- }
- }
-
- public void stopMeUp() {
- this.m_mascot.suspend();
- }
-
- public void startMeUp() {
- this.m_mascot.resume();
- }
-
- public void start() {
- if (this.m_mascot == null) {
- this.m_mascot = new Thread(this);
- this.m_mascot.start();
- }
-
- }
-
- public String getAppletInfo() {
- return "Name: mascot\r\n" + "Author: MS\r\n" + "Created with Microsoft Visual J++ Version 1.1";
- }
-
- public void run() {
- this.m_nCurrImage = 0;
- if (!this.m_fAllLoaded) {
- ((Component)this).repaint();
- this.m_Graphics = ((Component)this).getGraphics();
- this.m_Images = new Image[18];
- MediaTracker tracker = new MediaTracker(this);
- int i = 1;
-
- do {
- String strImage = "images/img00" + (i < 10 ? "0" : "") + i + ".gif";
- this.m_Images[i - 1] = ((Applet)this).getImage(((Applet)this).getDocumentBase(), strImage);
- tracker.addImage(this.m_Images[i - 1], 0);
- ++i;
- } while(i <= 18);
-
- try {
- tracker.waitForAll();
- this.m_fAllLoaded = !tracker.isErrorAny();
- } catch (InterruptedException var5) {
- }
-
- if (!this.m_fAllLoaded) {
- this.stop();
- this.m_Graphics.drawString("Error loading images!", 10, 40);
- return;
- }
-
- this.m_nImgWidth = this.m_Images[0].getWidth(this);
- this.m_nImgHeight = this.m_Images[0].getHeight(this);
- }
-
- ((Component)this).repaint();
-
- while(true) {
- try {
- this.displayImage(this.m_Graphics);
- if (this.direction == 1) {
- ++this.m_nCurrImage;
- if (this.m_nCurrImage == 18) {
- this.m_nCurrImage = 0;
- }
- } else {
- this.m_nCurrImage += -1;
- if (this.m_nCurrImage == -1) {
- this.m_nCurrImage = 17;
- }
- }
-
- Thread.sleep((long)this.speed);
- } catch (InterruptedException var6) {
- this.stop();
- }
- }
- }
-
- public void init() {
- ((Applet)this).resize(320, 240);
- String at = ((Applet)this).getParameter("speed");
- this.speed = at != null ? Integer.valueOf(at) : 50;
- at = ((Applet)this).getParameter("direction");
- this.direction = at != null ? Integer.valueOf(at) : 1;
- }
- }
-